<script>
import Vue from 'vue'

export default {
    onLaunch: async function (data) {
        // console.log(data);
        // this.$comFun.clearUserInfo();

        // 大逃杀game相关---start
        this.getNavH();
        // 大逃杀game相关---end

        // #ifdef H5
        if (data.path == undefined) {
            if (process.env.NODE_ENV == 'development') {
                uni.switchTab({
                    url: '/'
                });
            } else {
                uni.redirectTo({
                    url: '/'
                });
            }
        }
        this.$store.dispatch('setDeviceType', 'h5');
        // #endif

        // #ifdef APP-PLUS
        const that = this;
        uni.getSystemInfo({
            success: function (res) {
                // 客户端平台，值域为：ios、android  
                // console.log(res);
                that.$store.dispatch('setDeviceType', res.platform);
            }
        });
        // #endif

        let hideTabbarBool = false;
        let hideTabbarTime = setInterval(() => {
            if (hideTabbarBool) {
                clearInterval(hideTabbarTime);
            } else {
                uni.hideTabBar({
                    complete: ((res) => {
                        // console.log(res);
                        if (res.errMsg == "hideTabBar:ok") {
                            hideTabbarBool = true;
                        }
                    })
                });
            }
        }, 100);
        console.log('App Launch')
    },
    onShow: function () {
        uni.hideTabBar();
        console.log('App Show');
    },
    onHide: function () {
        console.log('App Hide')
    },
    methods: {
        getNavH() {
            // 获取导航高度；
            uni.getSystemInfo({
                success: res => {
                    let NavHeight = res.statusBarHeight;
                    this.$gameStore.NavHeight = NavHeight
                    this.$gameStore.safe_top = res.safeArea.top
                },
                fail(err) {
                    console.log(err);
                }
            })
        },
        //上传图片 count-选择图片数量
        async imgUpload(count, callback) {
            const that = this;
            uni.chooseImage({
                count: count, //默认9
                sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera '], //从相册选择
                success: async function (chooseImageRes) {
                    // console.log(JSON.stringify(chooseImageRes.tempFilePaths));
                    const tempFilePaths = chooseImageRes.tempFilePaths;
                    // console.log(tempFilePaths);
                    that.$comFun.openLoading();
                    let img_list = [];
                    for (var i = 0; i < tempFilePaths.length; i++) {
                        let res = await that.$request.uploadFile(tempFilePaths[i]);
                        // console.log(res);
                        if (res.code == 200) {
                            img_list.push(res.result);
                        }
                    }
                    that.$comFun.closeLoading();
                    callback(img_list);
                },
            });
        },
        //上传图片-会返回图片信息 count-选择图片数量
        async imgUploadHasInfo(count, callback) {
            const that = this;
            uni.chooseImage({
                count: count, //默认9
                sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera '], //从相册选择
                success: async function (chooseImageRes) {
                    // console.log(JSON.stringify(chooseImageRes.tempFilePaths));
                    const tempFilePaths = chooseImageRes.tempFilePaths;
                    // console.log(tempFilePaths);
                    that.$comFun.openLoading();
                    let img_list = [];
                    for (var i = 0; i < tempFilePaths.length; i++) {
                        let res = await that.$request.uploadFileHasInfo(tempFilePaths[i]);
                        // console.log(res);
                        if (res.code == 200) {
                            img_list.push(res.result);
                        }
                    }
                    that.$comFun.closeLoading();
                    callback(img_list);
                },
            });
        },
        async initAppUpdate() {
            const that = this;
            const res = await this.$request.get('public/getAppVersion', {});
            // console.log(res);
            // console.log(plus.runtime);
            // console.log(process.env.NODE_ENV);
            if (res.code == 200) {
                plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
                    // console.log(wgtinfo.versionCode);
                    const versionCode = wgtinfo.versionCode;
                    // const versionCode = 100;
                    // this.runtime = plus.runtime.versionCode + ',' + res.result.versionCode + ',' + (Number(res.result.versionCode) > Number(versionCode));
                    // console.log(this.runtime);
                    if (Number(res.result.versionCode) > Number(versionCode)) {
                        if (that.$store.state.deviceType == 'android') {
                            that.$store.dispatch('setAppUpdate', res.result.update_android_url)
                        } else if (that.$store.state.deviceType == 'ios') {
                            that.$store.dispatch('setAppUpdate', res.result.ios_url)
                        }
                    } else {
                        that.$store.dispatch('setAppUpdate', false)
                    }
                });
            }
        },
        async getConfigList() {
            // let data = {
            //     GIVE_PRO: 'givePro',
            //     EXCHANGE_GOODS_I_PRO: 'exchangeGoodsIPro',
            //     IS_JD_GAME: 'isJdGame',
            //     CARD_MAX_NUM: 'cardMaxNum',
            //     ANDROID_URL: 'androidUrl',
            //     COM_STORE_CARD_PRO: 'comStoreCardPro',
            //     ONE_STORE_PLEDGE: 'oneStorePledge',
            //     TWO_STORE_PLEDGE: 'twoStorePledge',
            //     THREE_STORE_PLEDGE: 'threeStorePledge',
            // }
            if (this.$store.state.configList == '') {
                const res = await this.$request.get('public/getConfigList', {});
                if (res.code == 200) {
                    this.$store.dispatch('setConfigList', res.result);
                    return res.result;
                } else {
                    return '';
                }
            } else {
                return this.$store.state.configList;
            }
        },
    }
}
</script>

<style lang="scss">
/*每个页面公共css */
@import "@/common/css/public.scss";
@import "@/common/css/iconfont_base/iconfont.css";
@import "@/common/css/iconfont_app/iconfont.css";
</style>
